<template>
	<div>
		<el-dialog title="肾损害剂量自定义" :visible.sync="dialogVisibleXiangHu" width="60%" :before-close="handleClose">
			<el-card style="margin-top:10px">
				<el-button type="primary" class="gs_add fr" @click="add">新增</el-button>
				<Graytable :tHead="tHead" :tData="tData"></Graytable>
				<pagination
					:total="query.total"
					:page.sync="query.page"
					:limit.sync="query.limit"
					@pagination="getList"/>
			</el-card>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleXiangHu = false">关 闭</el-button>
			</span>
		</el-dialog>
		<SelectDialog ref="selectDialog1" ctype="肾损害剂量" cintype="给药途径" :dataObj="nowData" :checkId="checkId1" @selectFun="selectFun"></SelectDialog>
		<SelectDialog ref="selectDialog2" ctype="肾损害剂量" cintype="疾病状态" :dataObj="nowData" :checkId="checkId2" @selectFun="selectFun"></SelectDialog>
		<SelectDialog ref="selectDialog3" ctype="肾损害剂量" cintype="检验值指标" :dataObj="nowData" :checkId="checkId3" @selectFun="selectFun"></SelectDialog>
		<sshSetCard ref="sshSetCard" @selectPop="selectPop" :gyData="gyData" :jbData="jbData" :sgnjyData="sgnjyData" :nowData="nowData"></sshSetCard>
	</div>
</template>

<script>
	import SelectDialog from "./selectDialog";
	import sshSetCard from "./sshSetCard";
	export default {
		components: {
			SelectDialog,
			sshSetCard
		},
		data () {
			return {
				query: {
				  total: 0,
				  page: 1,
				  limit: 10
				},
				dialogVisibleXiangHu:false,
				tHead:[
					{
						label:"操作",
						operate:["删除"],
						align:"center",
						width:"50px"
					},
					{
						prop:"aa",
						label:"警示"
					},
					{
						prop:"aa",
						label:"拦截"
					},
					{
						prop:"aa",
						label:"给药单位"
					},
					{
						prop:"aa",
						label:"给药途径编码"
					},
					{
						prop:"aa",
						label:"给药途径名称"
					},
					{
						prop:"degree_text",
						label:"肾功能描述"
					},
					{
						prop:"aa",
						label:"年龄段"
					},
					{
						prop:"diseaseStates",
						label:"疾病状态"
					},
					{
						prop:"aa",
						label:"计算方式"
					},
					{
						prop:"doseRange",
						label:"每次推荐剂量范围"
					},
					{
						prop:"dailyDose",
						label:"每日推荐剂量范围"
					},
					{
						prop:"operUser",
						label:"维护人"
					},
					{
						prop:"insTime",
						label:"维护日期"
					},
				],
				tData:[],
				ctype:"",
				checkId1:"",
				checkId2:"",
				checkId3:"",
				nowData:{},
				gyData:{id:"",name:""},
				jbData:{id:"",name:""},
				sgnjyData:{id:"",name:""},
			}
		},
		props:{
			dataObj:{
				required:true
			}
		},
		watch:{
			dataObj(val){
				this.nowData=val;
				console.log(val)
				this.resetTData(true);
			}
		},
		methods:{
			add () {
				this.$refs.sshSetCard.show();
			},
			selectPop (type,checkId,multi) {
				this.ctype=type;
				if(type == "给药"){
					this.checkId1 = checkId;
					this.$refs.selectDialog1.show()
				}else if(type == "疾病"){
					this.checkId2 = checkId;
					this.$refs.selectDialog2.show()
				}else{
					this.checkId3 = checkId;
					this.$refs.selectDialog3.show()
				}
			},
			selectFun(id,name){
				switch (this.ctype){
					case '给药':
						this.gyData={
							name:name,
							id:id
						}
						break;
					case '疾病':
						this.jbData={
							name:name,
							id:id
						}
						break;
					case "肾功能检验":
						this.sgnjyData={
							name:name,
							id:id
						};
						break;
				}
			},
			clearFun(type){
				if(this.ctype == "给药"){
					this.gyData = {
						id:"",
						name:""
					};
				}else if(this.ctype =="疾病"){
					this.jbData = {
						id:"",
						name:""
					};
				}else{
					this.sgnjyData={
						name:"",
						id:""
					};
				}
				this.checkId1="";
				this.checkId2="";
				this.checkId3="";
			},
			async getList () {
				let res=await this.$custom.listrenalDamageListFull({
					drugUniqueCode:this.nowData.drugUniqueCode,
					page:this.query.page,
					pageSize:this.query.limit
				})
				if(res){
					for(var i=0;i<res.rows.length;i++){
						if(res.rows[i].renalDescription == "1"){
							res.rows[i].degree_text="肾损害程度不明";
						}else if(res.rows[i].renalDescription == "2"){
							res.rows[i].degree_text="轻度肾损害";
						}else if(res.rows[i].renalDescription == "3"){
							res.rows[i].degree_text="中度肾损害";
						}else if(res.rows[i].renalDescription == "4"){
							res.rows[i].degree_text="重度肾损害";
						}else{
							res.rows[i].degree_text=res.rows[i].renalDescription
						}
						res.rows[i].insTime=this.$utils.timeFormat(res.rows[i].insTime)
					}
					this.tData=res.rows;
					this.query.total=res.total;
				}
			},
			show(){
				this.dialogVisibleXiangHu = true;
			},
			handleClose () {
				this.dialogVisibleXiangHu = false;
			},
			resetTData(flag){
				this.checkId1="";
				this.checkId2="";
				this.checkId3="";
				this.query={
					total:0,
					page:1,
					limit:10
				}
				this.tData=[];
				this.getList();
				if(!flag){
					this.$emit("changeFun")
				}
			},
			operateClick(item,row){
				this.$confirm('确定删除通用自定义?', '提示', {
					confirmButtonText: '确定删除',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.delFun(row);
				}).catch(() => {
				});
			},
			async delFun(row){
				let res=await this.$custom.listrenalDamageDelete({
					drugUniqueCodeRz:row.drugUniqueCodeRz,
					id:row.id
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				this.resetTData();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.gs_add{
		margin-bottom:20px;
	}
	.el-card {
		margin-left: 3px;
	}

	.SearchT {
		display: flex;
		justify-content: flex-end;
		height: 40px;
		align-items: center;
		background-color: #e6edf3;
		font-size: 14px;
	}

	.tableLable {
		flex: 1;
		text-align: left;
		margin-left: 15px;
		letter-spacing: 2px;
		font-size: 14px;
		color: #32a6f3;
		font-weight: bold;
	}

	/* .exportBtn {
  margin-right: 23px;
}
.BatchDeleBtn {
  margin-right: 15px;
} */
	.tableStyle {
		width: 100%;
		height: 100%;
	}

	.card-table {
		width: 100%;
		height: 75%;
	}

	.block {
		text-align: center;
		margin-top: 12px;
		margin-bottom: 12px;
	}

	.Btn {
		display: flex;
		flex: 1;
		flex-wrap: nowrap;
	}

	.dialogFirstRow>>>.el-input {
		width: 70px;
		margin-right: 10px;
	}

	.el-form-item.s_selectbox>>>.el-form-item__content {
		width: 80%;
	}
	/* .demo-form-inline>>>.el-form-item {
		margin-bottom: 0px;
	} */
</style>
